/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.brainstretch.models.analytics;

import java.util.*;
import javax.xml.bind.annotation.XmlRootElement;
import org.brainstretch.models.User;
import org.brainstretch.models.UserAction;
import org.brainstretch.models.UserQuiz;
import org.brainstretch.models.quizzes.Category;

/**
 *
 * @author mrodaitis
 */
@XmlRootElement
public class UserQuizData {
    
    private User user;
    private Map<Category, List<UserQuiz>> categoryMap;
    private List<UserQuizCategoryData> categoryData;
    
    public UserQuizData(User user) {
        this.user = user;
        categoryMap = new EnumMap<Category, List<UserQuiz>>(Category.class);
        createCategoricalData();
        categoryData = new ArrayList<UserQuizCategoryData>();
//        for(List<UserQuiz> quizzes: categoryMap.values()){
//            categoryData.add(new UserQuizCategoryData);
//        }
    }
    
    private void createCategoricalData(){
        List<UserQuiz> quizzes = user.getQuizzesTaken();
        for(UserQuiz quiz: quizzes){
            addQuizToCategory(quiz.getQuiz().getCategory(), quiz);
        }
    }

    
    private void addQuizToCategory(Category category, UserQuiz quiz){
        List<UserQuiz> currentQuizzes = categoryMap.get(category);
        if(currentQuizzes == null){
            currentQuizzes = new ArrayList<UserQuiz>();
            categoryMap.put(category, currentQuizzes);
        }
        currentQuizzes.add(quiz);
    }
    
    //NoArg for JPA/Deserialization
    public UserQuizData() {
    }
    
    
}
